<style>
    #after_out_type xm-select{
        min-width: 160px;
    }
    #after_group_id xm-select{
        min-width: 80px;
    }
</style>
<form class="layui-form"  action="{:url('mp/OutNodeProgress/outTail')}"   id="onClickOrderActionTplform" >

    <h2 class="layui-colla-title">订单号：{$info.client_ordernum}</h2>
    <table class="layui-table small-table">
        <thead>
        <tr>
            <th>MES单价(元)</th>
            <th>上次委外工厂</th>
            <th>上次委外情况</th>
            <th>委外名称</th>
            <th>委外类型</th>
            <th>委外工厂</th>
            <th>委外单价(元)</th>
            <th>委外数量(件)</th>
            <th>倍率</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>{$info.order_price}</td>
            <td></td>
            <td></td>
            <td></td>
            {if $type=="readonly"}
            <td >
                {$info.after_out_type_txt}
            </td>
            <td >
                {$info.after_group_name}
            </td>
            {else}
            <td id="after_out_type">
            </td>
            <td id="after_group_id">
            </td>
            {/if}
            <td>
                <input type="text" class=" layui-input" name="after_price" {if $type=="readonly"} readonly {/if} style="width:80px;"  value="{$info.after_price}" autocomplete="off" placeholder="请输入单价" lay-verify="number">
            </td>
            <td>
                <input type="text" class=" layui-input" name="after_num" {if $type=="readonly"} readonly {/if} style="width:80px;"  value="{$info.after_num}" autocomplete="off" placeholder="请输入数量" lay-verify="number">
            </td>
            {if $type=="readonly"}
            <td >
                {$info.after_unit}倍
            </td>
            {else}
            <td id="unti_all_price">
                0倍
            </td>
            {/if}
        </tr>
        </tbody>
    </table>
    <div class="layui-inline fr" style="margin: 20px 20px;">
        <input type="hidden" name="after_factory_id" value="{$info.after_factory_id}">
        <input type="hidden" name="order_id" value="{$info.id}">
        <button type="button" class="layui-btn layui-btn-normal" id="submitonClickOrderActionform">确定</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
    </div>
</form>


{include file="system@block/layui" /}
<script src="__PUBLIC_JS__/jquery.2.1.4.min.js?v={:config('hisiphp.version')}"></script>
<script src="__PUBLIC_JS__/xm-select/dist/xm-select.js?v={:config('hisiphp.version')}"></script>
<script type="text/javascript">
    var factorylist_tail= JSON.parse('{:json_encode($factorylist_tail)}');
    var factorylist_manual= JSON.parse('{:json_encode($factorylist_manual)}');
    var factorylist_all= JSON.parse('{:json_encode($factorylist_all)}');
    layui.use([ 'element', 'layer', 'laytpl', 'tool','laydate','table','form','flow'], function() {
        var element = layui.element;
        var layer = layui.layer;
        var $ = layui.jquery;
        var form = layui.form;
        var laytpl = layui.laytpl,laydate=layui.laydate ,table = layui.table;
        var flow = layui.flow;

        $(document).on('click','#submitonClickOrderActionform',function(e) {
            e.stopPropagation();
            $.ajax({
                type: "POST",
                url: "{:url('mp/OutNodeProgress/outTail')}",
                data: $('#onClickOrderActionTplform').serialize() ,
                dataType:"json",
                success: function(res){
                    if (res.code == 1) {
                        window.parent.location.reload();
                        parent.layer.closeAll();
                    } else {
                        layer.msg(res.msg, {icon: 2,anim: 6});
                    }
                }
            });
            return false;
        });
    });

    var after_group_id_select = xmSelect.render({
        el: '#after_group_id',
        name: 'after_group_id',
        language: 'zn',
        radio: true,
        data: [],
        on: function(data) {
            var arr = data.arr;
            $.each(data.arr, function(i, n){
                $('[name="after_factory_id"]').val(n['data-option']);
                $('#unti_all_price').html(n['data-option-unit']+"倍");
                return ;
            });
            if(arr.length==0){
                $('[name="after_factory_id"]').val(0);
                $('#unti_all_price').html("0倍");
            }
        }
    });

    var demo1 = xmSelect.render({
        el: '#after_out_type',
        name:'after_out_type',
        language: 'zn',
        data: [
            {name: '尾部', value: 3},
            {name: '专机', value: 4}
        ],
        on: function(data){
            //arr:  当前多选已选中的数据
            var arr = data.arr;
            var factorylist_tail_and_factorylist_manual={};
            switch (arr.length) {
                case 2:
                    factorylist_tail_and_factorylist_manual=factorylist_all;
                    break;
                case 1:
                    var flag=3;
                    $.each(data.arr, function(i, n){
                        if(n['value']==4){
                            flag=4;
                            return ;
                        }
                    });
                    switch (flag) {
                        case 3:
                            factorylist_tail_and_factorylist_manual=factorylist_tail;
                            break;
                        case 4:
                            factorylist_tail_and_factorylist_manual=factorylist_manual;
                            break;
                    }
                    break;
                default:
                    break;
            }
            var data=[];
            $.each(factorylist_tail_and_factorylist_manual, function(i, n){
                $.each(n.child, function(i2, n2){
                    data.push( {name: n2.group_name, value: n2.group_id,"data-option":n.ft_id,"data-option-unit":n2.unti_all_price});
                });
            });
            //数据初始化
            $('[name="after_factory_id"]').val(0);
            $('#unti_all_price').html("0倍");
            after_group_id_select.update({
                initValue: []
            });
            after_group_id_select.update({
                data: data
            });
        }
    });


</script>